var list = require('../../data/word-list.js')

const pageData = {
  data: {
    word:[],
    radmNum:[]
  },

//跳转到简单学习界面
  toGoSimple: function () {
    getApp().data.selectnum=1;
    for(var i=0;i<16;i++){
        var radm = Math.floor(Math.random() * 200);
        outer:
        while (1) {
          for (var j = 0; j < i; j++) {
            if (radm == this.data.radmNum[j]) {
              radm = Math.floor(Math.random() * 200);
              continue outer;
            }
          }
          break;
        }
        this.setData({ ['radmNum[' + i + '].text']: radm });
        console.log(this.data.radmNum[i].text);
      var word = list.wordList[radm]
      this.setData({ ['word[' + i + '].text']: word.content }); 
      i++;
      this.setData({ ['word[' + i + '].text']: word.definition});  
    }
    this.setWord();
    wx.redirectTo({
      url: '../wordlist1/wordlist1'
    });
  },
//跳转到一般学习界面
  toGoCommonly: function () {
    getApp().data.selectnum = 2;
    console.log(getApp().data.selectnum)
    for (var i = 0; i < 16; i++) {
      var radm = Math.floor(Math.random() * 200+200);
      outer:
      while (1) {
        for (var j = 0; j < i; j++) {

          if (radm == this.data.radmNum[j]) {
            radm = Math.floor(Math.random() * 200+200);
            continue outer;
          }
        }
        break;
      }
      this.setData({ ['radmNum[' + i + '].text']: radm });
      console.log(this.data.radmNum[i].text);
      var word = list.wordList[radm]
      this.setData({ ['word[' + i + '].text']: word.content });
      i++;
      this.setData({ ['word[' + i + '].text']: word.definition });
    }
    this.setWord();
    wx.redirectTo({
      url: '../wordlist1/wordlist1'
    });
  },
//跳转到困难学习界面
  toGoHard: function () {
    getApp().data.selectnum = 3;
    console.log(getApp().data.selectnum)
    for (var i = 0; i < 16; i++) {
      var radm = Math.floor(Math.random() * 200+400);
      outer:
      while (1) {
        for (var j = 0; j < i; j++) {

          if (radm == this.data.radmNum[j]) {
            radm = Math.floor(Math.random() *200+400);
            continue outer;
          }
        }
        break;
      }
      this.setData({ ['radmNum[' + i + '].text']: radm });
      console.log(this.data.radmNum[i].text);
      var word = list.wordList[radm]
      this.setData({ ['word[' + i + '].text']: word.content });
      i++;
      this.setData({ ['word[' + i + '].text']: word.definition });
    }
    this.setWord();
    wx.redirectTo({
      url: '../wordlist1/wordlist1'
    });
  },
  goToRule: function(){
    wx.redirectTo({
      url: '../rule/rule'
    });
  },
  setWord: function () {
    wx.setStorageSync('1', this.data.word[0].text),
      wx.setStorageSync('2', this.data.word[2].text),
      wx.setStorageSync('3', this.data.word[4].text),
      wx.setStorageSync('4', this.data.word[6].text),
      wx.setStorageSync('5', this.data.word[8].text),
      wx.setStorageSync('6', this.data.word[10].text),
      wx.setStorageSync('7', this.data.word[12].text),
      wx.setStorageSync('8', this.data.word[14].text),
      wx.setStorageSync('9', this.data.word[15].text),
      wx.setStorageSync('10', this.data.word[13].text),
      wx.setStorageSync('11', this.data.word[11].text),
      wx.setStorageSync('12', this.data.word[9].text),
      wx.setStorageSync('13', this.data.word[7].text),
      wx.setStorageSync('14', this.data.word[5].text),
      wx.setStorageSync('15', this.data.word[3].text),
      wx.setStorageSync('16', this.data.word[1].text)
  }
};
Page(pageData);